package aoj.no_1100;

import java.util.Scanner;

public class No_1104 {
	
	private static final int UP = 1;
	private static final int RIGHT = 2;
	private static final int DOWN = 3;
	private static final int LEFT = 4;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			//initialize
			int width = sc.nextInt();
			int height = sc.nextInt();
			if(height == 0 && width == 0)
				break;
			
			int x = 1;
			int y = 1;
			int direction = UP;
			
			while(true) {
				String command = sc.next();
				if(command.equals("STOP")) {
					System.out.printf("%d %d\n", x, y);
					break;
				}
				else if(command.equals("FORWARD")) {
					int step = sc.nextInt();
					switch(direction) {
						case UP:
							y = (y + step) > height ? height : (y + step);
							break;
						case RIGHT:
							x = (x + step) > width ? width : (x + step);
							break;
						case DOWN:
							y = (y - step) < 1 ? 1 : (y - step);
							break;
						case LEFT:
							x = (x - step) < 1 ? 1 : (x - step);
							break;
					}
				}
				else if(command.equals("BACKWARD")) {
					int step = sc.nextInt();
					switch(direction) {
						case UP:
							y = (y - step) < 1 ? 1 : (y - step);
							break;
						case RIGHT:
							x = (x - step) < 1 ? 1 : (x - step);
							break;
						case DOWN:
							y = (y + step) > height ? height : (y + step);
							break;
						case LEFT:
							x = (x + step) > width ? width : (x + step);
							break;
					}
				}
				else if(command.equals("RIGHT")) {
					direction += 1;
					if(direction == 5)
						direction = 1;
				}
				else if(command.equals("LEFT")) {
					direction -= 1;
					if(direction == 0)
						direction = 4;
				}
				else {
					System.err.println("Invalid Command!");
					System.exit(0);
				}
			}
		}
	}
}
/*
6 5
FORWARD 3
RIGHT
FORWARD 5
LEFT
BACKWARD 2
STOP
3 1
FORWARD 2
STOP
0 0 
*/
